package com.github.baichuan.file.rest.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(value = "repository.name",havingValue = "aliyun-oss")
@Slf4j
public class AliyunOss {
    @Value("${repository.aliyun-oss.endpoint}")
    private String endpoint;

    @Value("${repository.aliyun-oss.access-key-id}")
    private String accessKeyId;

    @Value("${repository.aliyun-oss.access-key-secret}")
    private String accessKeySecret;

    @Bean
    public OSS client(){
        log.info("File repository is aliyun-oss.");

        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }
}
